var listdata = [];
var total = ''
// 用户ID
let id = getUrlParam("id");
$(function () {
    GetUserRole();
});
//获取用户权限
function GetUserRole() {
    // let thisdata = [];
    // thisdata.push(InitRole(id));
    let USERdata = InitRole(id);
    if (USERdata != null) {
        chooseWait('all');
        InitDataWait();
    }
    else OpenErrmsg("../../web/errhtml/404.html");
}

function chooseWait(type) {
    $('#btn_all').removeClass("labelstyleChoose labelstyle");
    $('#btn_gd').removeClass("labelstyleChoose labelstyle");
    $('#btn_dd').removeClass("labelstyleChoose labelstyle");
    $('#btn_rb').removeClass("labelstyleChoose labelstyle");

    $('#btn_all').addClass(type == "all" ? "labelstyleChoose" : "labelstyle");
    $('#btn_gd').addClass(type == "gd" ? "labelstyleChoose" : "labelstyle");
    $('#btn_dd').addClass(type == "dd" ? "labelstyleChoose" : "labelstyle");
    $('#btn_rb').addClass(type == "rb" ? "labelstyleChoose" : "labelstyle");
    InitDataWait();
}
function InitDataWait() {
    getlistdata(1, 10)
    $('#dg_WaitList').datagrid({
        data: listdata
    });
    $('#dg_pagination').pagination({
        total: total,
        onSelectPage: function (pageNumber, pageSize) {
            getlistdata(pageNumber, pageSize)
            $('#dg_WaitList').datagrid({
                data: listdata
            });
        },
        onRefresh: function (pageNumber, pageSize) {
            $('#dg_pagination').pagination('refresh', {	// 改变选项并刷新分页栏信息
                total: total,
                pageNumber: 1
            });
            getlistdata(1, 10)
            $('#dg_WaitList').datagrid({
                data: listdata
            });
        }
    });
}
let path = getPath();
var words = ''
var dbStart = ''
var dbEnd = ''
function getlistdata(pageNumber, pageSize) {
    var words = $("#txt_Search")[0].value
    var dbStart = $("#db_Start")[0].value
    var dbEnd = $("#db_End")[0].value
    let url = path + '/ls172/ls172-workorder/getBacklogList'
    var params = {
        "data": words,
        "endTime": dbEnd,
        "pageNum": pageNumber,
        "pageSize": pageSize,
        "startTime": dbStart
    }
    $.ajax({
        url: url,
        type: "post",
        async: false,
        dataType: "json",
        headers: {
            Accept: "application/json",
            "Content-Type": "application/json"
        },
        data: JSON.stringify(params),

        success: function (data) {
            listdata = data.data.records
            total = data.data.total
            document.getElementById('btn_all').innerText = '全部待办（'+total+'）'
        },
        error: function (data) {
            console.log("code", data);
        }
    });
}
// 重置按钮
function ReInitDataWait() {
    $('#db_Start').datebox('setValue', '');
    $('#db_End').datebox('setValue', '');
    InitDataWait();
}
function chooseSearch() {
    var isok = $("#ck_search").is(':checked');
    if (isok) {
        $("#div_Search").show();
        $('#db_Start').datebox('setValue', dbStart);
        $('#db_End').datebox('setValue', dbEnd);
    }
    else {
        $("#div_Search").hide();
        $('#db_Start').datebox('setValue', "");
        $('#db_End').datebox('setValue', "");
    }
}
function formaterPlanWork(value, row) {
    let str = ' <label style="color:#589BD8;margin: 20px;">' + row.planwork + '</label>';
    return str;
}
function formaterIndex(value, row, index) {
    return '<a href="#" style="color:#589BD8;text-decoration:none;margin-top: 20px;">' + (parseInt(index) + 1) + '</a>';
}
function formaterop(value, row) {
    let val = '<a href="#" style="color:#589BD8;text-decoration:none;margin-top: 20px;padding:10px"  onclick="openmaxioWin()">详情</a>';
    val += '<a href="#" style="color:#589BD8;text-decoration:none;margin-top: 20px;padding:10px" onclick="openmaxioWin()" >处理</a>';
    return val;
}
function openmaxioWin() {
    let windowObjectReference = window.open();
    windowObjectReference.location.href = "_blank.html";
}
